﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BOSS.Framework.Search.UrlBuilder;

namespace BOSS.Framework.Search.Context
{
    /// <summary>
    /// 日期范围过滤条件类
    /// </summary>
    [Serializable]
    public class RangeDateFilterPart : RangeValueFilterPart<DateTime>
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        public RangeDateFilterPart(string fieldName, DateTime minValue, bool includeMinValue, DateTime maxValue, bool includeMaxValue)
        {
            this.FieldName = fieldName;
            this.MinValue = minValue;
            this.IncludeMinValue = includeMinValue;
            this.MaxValue = maxValue;
            this.IncludeMaxValue = includeMaxValue;
        }

        /// <summary>
        /// 构造 URL
        /// </summary>
        /// <param name="urlBuilder"></param>
        public override void BuildUrl(IUrlBuilder urlBuilder)
        {
            urlBuilder.SetFilter(this.FieldName, this.MinValue, this.IncludeMinValue, this.MaxValue, this.IncludeMaxValue);
        }

        /// <summary>
        /// 获取值
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        protected override object GetValue(DateTime value)
        {
            return value.ToString("yyyyMMdd");
        }
    }
}
